/**
 * Perform the element default action.
 *
 * @param {JSEvent} event the event that triggered the action
 *
 * @properties={typeid:24,uuid:"8B307F33-E1E4-4F49-AC16-26A66088EC63"}
 */
function listar(event) {
	var $globales = solutionModel.getGlobalVariables()
	
	var a2 = $globales.filter(function(item) { return item.name.indexOf('z', 0) == 0; });
	if (a2.length == 0)
	{
		application.output('Variables globales no encontradas')
		return false
	}
	databaseManager.setAutoSave(false)
	/** @type {JSFoundSet<db:/fwk_navigation_infocom/param_app>}*/
	var $fs = databaseManager.getFoundSet('fwk_navigation_infocom','param_app')
	for (var i = 0 ; i < a2.length ; i++)
	{
		if (!buscarDuplicado(a2[i].name,application.getSolutionName()))
		{
			$fs.newRecord()
			
			$fs.nombre_var = a2[i].name
			$fs.solucion = application.getSolutionName()
	
			switch( a2[i].variableType )
			{
				case JSVariable.TEXT:
				{
					$fs.tipo = 1
					$fs.valor_txt = globals[a2[i].name]
					break;
				}
				case JSVariable.INTEGER:
				{
					$fs.tipo = 2
					$fs.valor_int = globals[a2[i].name]
					break;
				}
				case JSVariable.NUMBER:
				{
					$fs.tipo = 3
					$fs.valor_num = globals[a2[i].name]
					break;
				}
			}
		}
		application.output(a2[i].name + ' = ' + globals[a2[i].name])
	}
	databaseManager.startTransaction()
	if (databaseManager.saveData())
	{
		databaseManager.commitTransaction()
		databaseManager.setAutoSave(true)
		globals.DIALOGS.showInfoDialog('Aviso','Proceso OK','OK')
	}
	else
	{
		databaseManager.rollbackTransaction()
		databaseManager.revertEditedRecords()
		databaseManager.setAutoSave(true)
		globals.DIALOGS.showWarningDialog('Aviso','Error en el proceso','OK')
	}
	return true
}

/**
 * @param {String} nombre
 * @param {String} solucion
 * 
 * @properties={typeid:24,uuid:"E9B0D42D-F5C5-4757-AECD-B90BF52D6510"}
 */
function buscarDuplicado(nombre, solucion)
{
	var $sql = 'SELECT nombre_var FROM param_app WHERE nombre_var = ? AND solucion = ? ' +
				'UNION SELECT nombre_var FROM param_usr WHERE nombre_var = ? AND solucion = ?'
	var $args = [nombre, solucion, nombre, solucion]
	var $ds = databaseManager.getDataSetByQuery('fwk_navigation_infocom',$sql,$args,-1)
	return ($ds.getMaxRowIndex() != 0)
}